﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Configuration;


namespace AirplaneReservation
{
    public partial class FlightDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void view_Click(object sender, EventArgs e)
        {
            TextBox lb = (TextBox)WUC_DepartDate.FindControl("txtDate");

            SqlConnection ccon = new SqlConnection(ConfigurationManager.ConnectionStrings["airplaneConnectionString"].ToString());
            ccon.Open();

            string sql = "select Depart_Time, CONVERT(varchar(10), Arrival, 101) AS Arrival_Date, Right(CONVERT(varchar, Arrival, 100), 7) AS Arrival_Time, Destination from View_FlightDetails where Flight_ID='" + flightNo.Text + "' and Depart_Date='" + lb.Text + "'";
            SqlDataAdapter da = new SqlDataAdapter(sql, ccon);
            DataTable dt = new DataTable();
            da.Fill(dt);

            int count = dt.Rows.Count;
            if (count == 0)
            {
                Label1.Text = "There is no flight match to the conditions";
                GridView1.Visible = false;
            }
            else
            {
                GridView1.DataSource = dt;
                GridView1.DataBind();
                GridView1.Visible = true;
                Label1.Text = "";
            }
        }
    }
}